package com.wiki.KBS.Controller;

import com.wiki.KBS.request.CategoryReq;
import com.wiki.KBS.request.CategorySaveReq;
import com.wiki.KBS.response.CategoryQueryResp;
import com.wiki.KBS.response.CommonResp;
import com.wiki.KBS.response.PageResp;
import com.wiki.KBS.services.CategoryService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @RequestMapping("/all")
    public CommonResp categoryAll(){
        CommonResp<List<CategoryQueryResp>> resp = new CommonResp<>();
        List<CategoryQueryResp> categorys = categoryService.categoryAll();
        resp.setMessage("category all 数据获取成功！");
        resp.setContent(categorys);
        return resp;
    }

    @RequestMapping("/list")
    public CommonResp categoryList(@Valid CategoryReq req){
        CommonResp<PageResp<CategoryQueryResp>> resp = new CommonResp<>();
        PageResp<CategoryQueryResp> categorys = categoryService.categoryList(req);
        resp.setMessage("category list数据获取成功！");
        resp.setContent(categorys);
        return resp;
    }

    @PostMapping("/save")
    public CommonResp save(@Valid @RequestBody CategorySaveReq req){
        CommonResp resp = new CommonResp<>();
        categoryService.save(req);
        return resp;
    }

    @DeleteMapping("/delete/{id}")
    public CommonResp delete(@PathVariable Long id){
        CommonResp resp = new CommonResp<>();
        categoryService.delete(id);
        return resp;
    }
}
